﻿using ScreenCapture.Common;
using ScreenCapture.ViewModels;
using System;
using System.Windows;


namespace ScreenCapture.Views
{
    /// <summary>
    /// ErrorWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ErrorWindow : Window
    {
        // 异常窗口显示的异常对象
        private readonly Exception _exception;
        // 异常窗口现实的额异常信息(在异常对象里面其实就是Exception.Message)
        private readonly string? _message;

        public ErrorWindow(Exception Exception, string? Message = null)
        {
            _exception = Exception;
            _message = Message;
            InitializeComponent();

            // 如果判断UI使用的上下文是ExceptionViewModel就初始化ExceptionVIiewModel中的属性.
            if (DataContext is ExceptionViewModel vm)
            {
                // 异常信息初始化
                vm.Init(Exception, Message);
            }
        }

        private void OpenFFmpegLog_OnClick(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 查看详情按钮被点击,跳转到详细异常信息窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewDetails_OnClick(object sender, RoutedEventArgs e)
        {
            new ExceptionWindow(_exception, _message).ShowAndFocus();
        }
    }
}





